import {TSelectOptions} from "@/common-data-source/type";
import {useEffect, useState} from "react";
/**
 * @author DongPing
 * 2022/1/18 13:49
 *
 * 用来管理组件里面的下拉框数据的hook
 * P 是查询数据的方法的参数类型
 * */
export function useSelectOptions<P>(queryFunction: (p: P) => Promise<TSelectOptions>, p?: P): TSelectOptions {
	const [options, setOptions] = useState<TSelectOptions>([]);
	useEffect(function () {
		// @ts-ignore
		queryFunction(p).then(setOptions);
	}, [p])
	return options;
}
